/*
 * @Author: CodeHare
 * @Date: 2023-09-11 08:39:08
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2024-04-10 09:46:23
 * @Description: 
 */
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:yt_devops/components/log_utils.dart';
import 'package:yt_devops/model/role_model.dart';
import 'package:yt_devops/model/user_model.dart';
import 'package:yt_devops/pages/alarm/alarm_home/alarm_home_view.dart';
import 'package:yt_devops/pages/devices/child_device_list/child_device_list_binding.dart';
import 'package:yt_devops/pages/devices/child_device_list/child_device_list_view.dart';
import 'package:yt_devops/pages/devices/device_list/device_list_model.dart';
import 'package:yt_devops/pages/tabs/device_tab/device_tab_binding.dart';
import 'package:yt_devops/pages/tabs/device_tab/device_tab_view.dart';
import 'package:yt_devops/routers/router_path.dart';
import 'package:yt_devops/user_entity_manager.dart';
import 'package:yt_devops/utils/enums.dart';
import 'package:yt_devops/utils/func_utils.dart';

import '../pages/devices/child_device_list/child_device_list_controller.dart';
import 'constants/permission_page_constant.dart';

class NavigateUtils {
  static Future? toTaskDetail(int id, TaskType type) {
    String path = '';
    if (type == TaskType.install) {
      path = RouterPath.installTaskDetail;
    } else if (type == TaskType.maintenance) {
      path = RouterPath.repairTaskDetail;
    } else {
      path = RouterPath.reportTaskDetail;
    }
    return Get.toNamed('$path/$id', arguments: {
      'id': id,
    });
  }

  ///点击了下级设备
  static Future? toChildDevices(
    DeviceListModel device,
    int deviceId,
  ) {
    var id = deviceId.toString();

    return Get.to(
        () => ChildDeviceListPage(
              tagName: id,
            ),
        routeName: '${RouterPath.childDeviceList}/$id',
        binding: ChildDeviceListBinding(tag: id),
        arguments: {
          'device': device,
        });
  }

  /// 主设备详情
  static Future? toDeviceDetail(int deviceId, int productType, String name,
      ConnectStatusType connectStatus,
      {int? productId,
      required DeviceListModel? deviceTree,
      List<int> subDevicesIdList = const [],
      List<String> subDevicesNameList = const []}) {
    var id = deviceId.toString();

    return Get.to(
        () => DeviceTabPage(
              tagName: id,
            ),
        routeName: '${RouterPath.deviceTab}/$id',
        binding: DeviceTabBinding(tagName: id),
        arguments: {
          'deviceId': deviceId,
          'type': productType,
          'deviceName': name,
          'productId': productId,
          'connectStatus': connectStatus,
          'subDevicesIdList': subDevicesIdList,
          'subDevicesNameList': subDevicesNameList,
          'deviceTree': deviceTree
        });
  }

  /// 告警
  static Future? toAlarm({
    int? siteId,
    String? siteName,
    int? deviceId,
    String? deviceName,
    AlarmPageType? alarmPageType,
  }) {
    var tag = siteId != null && siteName != null
        ? '$siteName/$siteId'
        : '$deviceName/$deviceId';
    return Get.to(
      () => AlarmHomePage(
        tagName: tag,
        siteId: siteId,
        siteName: siteName,
        deviceId: deviceId,
        deviceName: deviceName,
        alarmPageType: alarmPageType,
      ),
      routeName: '${RouterPath.alarmHome}/$tag',
      binding: DeviceTabBinding(tagName: tag),
    );
  }

  /// 告警
  static Future? toAlarmDetail(
    int id,
  ) {
    return Get.toNamed(
      '${RouterPath.alarmDetail}/$id',
      arguments: {
        'id': id,
      },
    );
  }

  // 根据角色获取主页路由
  static String getHomeTabByRole([UserModel? user]) {
    // List<RoleModel>? roles = user?.roles ?? UserEntityManager().userModel.roles;
    // int? type = roles != null && roles.isNotEmpty ? roles[0].roleId : null;
    // int? type = UserEntityManager().userModel.org?.type;
    // // Log.d('UserEntityManagertype===' + type.toString());
    // if (type == RoleType.installer.value) {
    //   // 安装商
    return RouterPath.productManageHome;
    // } else if (type == RoleType.owner.value) {
    //   // 业主
    //   return RouterPath.ownerHome;
    // } else {
    //   // 产品管理员
    //   return RouterPath.productManageHome;
    // }
  }
}
